<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <link href="/URMS/lib/layui-v2.5.5/css/layui.css" media="all" rel="stylesheet">
    <link href="/URMS/css/public.css" media="all" rel="stylesheet">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form action="" class="layui-form layuimini-form" style="text-align: center;width: 800px">

    <input id="id" name="id" th:value="${editRole.id}" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label required">角色名</label>
        <div class="layui-input-block">

            <input class="layui-input" lay-reqtext="角色名不能为空" lay-verify="required" name="name" placeholder="请输入角色名"
                   th:value="${editRole.name}"
                   type="text">

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block" th:switch="${editRole.status}">
            <p th:case="'1'">
                <input checked="checked" lay-skin="switch" lay-text="ON|OFF" name="status"
                       type="checkbox">
            </p>
            <p th:case="'0'">
                <input lay-skin="switch" lay-text="ON|OFF" name="status" type="checkbox">
            </p>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-filter="saveBtn" lay-submit>确认保存</button>
        </div>
    </div>
</form>
</div>
<script charset="utf-8" src="/URMS/lib/layui-v2.5.5/layui.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            if (data.field.status == "on") {
                data.field.status = "1";
            } else {
                data.field.status = "0";
            }
            let dataRole = data.field
            var index = layer.confirm(JSON.stringify(data.field), {
                title: '最终的提交信息'

            }, function () {
                $.ajax({
                    url: "/URMS/sysRole/editSubmitRole",
                    data: dataRole,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        if (data == false) {
                            layer.msg("修改失败");
                            return false
                        } else {
                            layer.msg("修改成功")
                        }
                    },
                    error: function (XMLHttpResponse) {
                        layer.msg("登录出错");
                    }
                });

                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            });

            return false;
        });

    });
</script>
</body>
</html>